
package syspizza.massa.factory;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import syspizza.massa.Massa;
import syspizza.massa.MassaDoce;
import syspizza.massa.MassaTradicional;
import syspizza.massa.MassaVegetariana;
import syspizza.massa.comportamento.CustoFornoALenha;
import syspizza.massa.comportamento.CustoFornoEletrico;
import syspizza.massa.comportamento.CustoFornoIndustrial;


public class MassaFactory {

    //singleton na factory, soh precisa de uma instancia
    private static MassaFactory instance;
    private static Map<String, Massa> massas;

    private MassaFactory() {
    }

    public static MassaFactory getInstance() {
        if (instance == null) {
            instance = new MassaFactory();
            LoadMassas();
        }
        return instance;
    }

    public Massa getMassa(String chave) {
        Massa massa = null;     
        massa = massas.get(chave);     
        return massa;
    }

    public List<String> getFactories() {
        List lista = Arrays.asList(massas.keySet().toArray());
        return lista;
    }

    private static void LoadMassas() {
        massas = new HashMap<>();
        massas.put("Doce", new MassaDoce(new CustoFornoEletrico()));
        massas.put("Tradicional", new MassaTradicional(new CustoFornoALenha()));
        massas.put("Vegetariana", new MassaVegetariana(new CustoFornoIndustrial()));
    }

}
